package com.zlzlib.common.bean;

import lombok.Data;

import java.util.List;

/**
 * 统一返回对象
 *
 * @DateTime: 2023/2/14 16:06
 * @Author zlz
 * @Version 1.0
 */
@Data
public class ResultVo {
    /**
     * 响应代码
     */
    private int code;
    /**
     * 消息
     */
    private String message;
    /**
     * 对象数据
     */
    private Object data;

    /**
     * 列表数据
     */
    private List<?> dataList;

    public ResultVo() {
    }

    public ResultVo(ResultCode result) {
        this.code = result.getCode();
        this.message = result.getMsg();
    }

    public ResultVo(ResultCode result, Object data) {
        this.code = result.getCode();
        this.message = result.getMsg();
        this.data = data;
    }

    public ResultVo(ResultCode result, Object data, String msg) {
        this.code = result.getCode();
        this.message = msg;
        this.data = data;
    }

    public ResultVo(ResultCode result, List<?> dataList) {
        this.code = result.getCode();
        this.message = result.getMsg();
        this.dataList = dataList;
    }

    public ResultVo(ResultCode result, List<?> dataList, String msg) {
        this.code = result.getCode();
        this.message = msg;
        this.dataList = dataList;
    }

    public ResultVo(ResultCode result, String msg) {
        this.code = result.getCode();
        this.message = msg;
    }

    public static ResultVo success() {
        return new ResultVo(ResultCode.SUCCESS);
    }

    public static ResultVo success(Object data) {
        return new ResultVo(ResultCode.SUCCESS, data);
    }

    public static ResultVo success(Object data, String msg) {
        return new ResultVo(ResultCode.SUCCESS, data, msg);
    }

    public static ResultVo success(String msg) {
        return new ResultVo(ResultCode.SUCCESS, null, msg);
    }

    public static ResultVo success(List<?> dataList) {
        return new ResultVo(ResultCode.SUCCESS, dataList);
    }

    public static ResultVo success(List<?> dataList, String msg) {
        return new ResultVo(ResultCode.SUCCESS, dataList, msg);
    }

    public static ResultVo error() {
        return new ResultVo(ResultCode.FAILED);
    }

    public static ResultVo error(String msg) {
        return new ResultVo(ResultCode.FAILED, msg);
    }

    public static ResultVo tokenError() {
        return new ResultVo(ResultCode.LOSS_TOKEN);
    }

    public static ResultVo update(Object data) {
        return new ResultVo(ResultCode.UPDATE,data);
    }

}
